Assignemnt #53 and 51th Program
Code
///Name: Derrick Andreasen
///Period: 7
///Program name: 51st Program
///File name: Fift4Prog.java
///Date Finished:11/4/2015
import java.util.Random;
public class Fift4Prog
{
public static void main( String[] args )
{
Random r = new Random();
int x = 1 + r.nextInt(10);
System.out.println( "My random number is " + x );
System.out.println( "Here are some numbers from 1 to 5!" );
System.out.print( 1 + r.nextInt(5) +" " );
System.out.print( 1 + r.nextInt(5) +" " );
System.out.print( 1 + r.nextInt(5) +" " );
System.out.print( 1 + r.nextInt(5) +" " );
System.out.print( 1 + r.nextInt(5) +" " );
System.out.print( 1 + r.nextInt(5) +" " );
System.out.println( "" );
System.out.println( "Here are some numbers from 1 to 100!" );
System.out.print( 1 + r.nextInt(100) +"\t" );
System.out.print( 1 + r.nextInt(100) +"\t" );
System.out.print( 1 + r.nextInt(100) +"\t" );
System.out.print( 1 + r.nextInt(100) +"\t" );
System.out.print( 1 + r.nextInt(100) +"\t" );
System.out.print( 1 + r.nextInt(100) +"\t" );
System.out.println( "" );
int num1 = 1 + r.nextInt(10);
int num2 = 1 + r.nextInt(10);
if(num1 == num2)
{
System.out.println( "The random numbers were the same! Weird." );
}
if(num1 != num2)
{
System.out.println( "The random numbers were different! Not too suprising, actually." );
}
}
}
Picture of the output